package net.optix.ip.vo
{
	import mx.collections.ArrayCollection;
	
	public class TrackClientVO
	{
		public var invenDisNum:int;
		public var invenPubNum:int;
		public var patentsFilesNum:int;
		public var patentsIssuedNum:int;
		public var patentsAbandonedNum:int;
		public var trademarksRegisteredNum:int;
		public var tradesecretsProtectedNum:int;
		public var copyrightsRegisteredNum:int;
		
		public var quarter:String;
		
		public static function purseFirst(tracks:ArrayCollection):ArrayCollection
		{
			var arrays:ArrayCollection	=	new ArrayCollection();
			
			var year:int	=	0;
			var arr:ArrayCollection	;
			for(var i:int=0; i<tracks.length; i++)
			{
				var track:TrackDocketVO	=	TrackDocketVO(tracks[i]);
				if(track.year != year && track.year != 0)
				{
					if(i==0)
					{
						arr	=	new ArrayCollection();
						arr.addItem(track);
					}
					else
					{
						var tem:ArrayCollection	=	TrackClientVO.purseSecond(arr,year);
						for(var j:int=0; j<tem.length; j++)
						{
							arrays.addItem(tem[j]);
						}
						arr	=	new ArrayCollection();
						arr.addItem(track);
					}
					
				}
				else
				{
					arr.addItem(track);
				}
				year	=	track.year;
			}
			var tem:ArrayCollection	=	TrackClientVO.purseSecond(arr,year);
			for(var j:int=0; j<tem.length; j++)
			{
				arrays.addItem(tem[j]);
			}
			for(var i:int=0; i<arrays.length; i++)
			{
				var vo:TrackClientVO	=	arrays[i];
				trace(vo.quarter);
			}
			return arrays;
		}
		
		public static function purseSecond(tracks:ArrayCollection,year:int):ArrayCollection
		{	
			var i:int;
			var trackClientVOs:ArrayCollection	=	new ArrayCollection();
			for(i=0 ;i<4; i++)
			{
				var quarter:TrackClientVO	=	new TrackClientVO();
				quarter.quarter				=	"Q"+(i+1)+year.toString().substr(2,2);
				trackClientVOs.addItem(quarter);
			}
			
			var track:TrackDocketVO;
			var month:int;
			var trackClientVO:TrackClientVO;
			
			for(i=0 ; i<tracks.length; i++)
			{
				track	=	TrackDocketVO(tracks[i]);
				month	=	track.month%4;
				trackClientVO	=	trackClientVOs[month];
				switch(track.type)
				{
					case 0:
						trackClientVO.invenDisNum	+=	1;
						break;
					case 1:
						trackClientVO.invenPubNum	+=	1;
						break;
					case 2:
						trackClientVO.patentsFilesNum	+=	1;
						break;
					case 3:
						trackClientVO.patentsIssuedNum	+=	1;
						break;
					case 4:
						trackClientVO.patentsAbandonedNum	+=	1;
						break;
					case 5:
						trackClientVO.trademarksRegisteredNum	+=	1;
						break;
					case 6:
						trackClientVO.tradesecretsProtectedNum	+=	1;
						break;
					case 7:
						trackClientVO.copyrightsRegisteredNum	+=	1;
						break;
				}		
			}
			return trackClientVOs;
		}
	}
}